<?php

/**
* OverviewMapModule.class.php
*
* Module responsable for code hunt
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once("Auth/Auth.php");
require_once("framework/config.php");
require_once("UserAuth.php");
require_once("framework/PageModule.class.php");
require_once("HTML/QuickForm.php");
require_once("HTML/QuickForm/Renderer/Default.php");
require_once("HTML/Template/IT.php");
require_once("framework/Wurfl.class.php");


// {{{ AuthForm

class OverviewMapModule extends PageModule 
{
    
    
    private $dbh = null;

    function OverviewMapModule()
    {

        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN'); 
        $this->dbh = new PDO($options['dsn_string']);
        $this->dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

    }

    // {{{ getContent()

    
    /**
    * getContent()
    *
    */

    function getContent()
    {

        trigger_error("ENTER OverviewMapModule::getContent()", E_USER_NOTICE);

        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL'); 
	    $options = &PEAR::getStaticProperty('CONFIG_INI','TEMPLATES');     
        $tpl = new HTML_Template_IT($options["templates_dir"]);
        $tpl->loadTemplatefile("overview_map.tpl.xhtml",true,true);


        $height = Wurfl::deviceFactory()->getCapability("max_image_height");
        $tpl->setVariable("HEIGHT", $height > 640 ? 640 : $height );

        $width = Wurfl::deviceFactory()->getCapability("max_image_width");
        $tpl->setVariable("WIDTH", $width > 640 ? 640 : $width );

        $options = &PEAR::getStaticProperty('CONFIG_INI','GOOGLEMAPKEY'); 
        $tpl->setVariable("SENSOR","true");
                    
        $sth = $this->dbh->prepare('SELECT geocode,(SELECT name FROM guide_name WHERE guide_name.locale = "'.LocalizationSingleton::getLocale().'" AND guide_id = guide.rowid) AS name FROM guide WHERE publish = 1 ORDER BY name ASC');
        $sth->execute();

        $result = $sth->fetchAll(PDO::FETCH_ASSOC);
	
	    $tpl->setVariable("ALT",sprintf(_('Mapa poglądowa (%s)'),count($result)));

        $indexArray = array();
        foreach (range(1, 9) as $number) {
           $indexArray[] = $number;
        }
        foreach (range('A', 'Z') as $letter) {
           $indexArray[] = $letter;
        }
        

        if ( count($result) )
        {
            foreach($result as $key => $value)
            {
                if ( $value['geocode'] ) 
                {

                    $tpl->setCurrentBlock('marker_row');
                    $index = $key%count($indexArray);
                    $tpl->setVariable("MARKERLABEL",$indexArray[$index]);
                    $tpl->setVariable("MARKERSIZE","mid");
                    $tpl->setVariable("GEOCODE",urlencode($value['geocode']));
                    $tpl->parseCurrentBlock('marker_row');
        
                }
            }
            
        }
        return $tpl->get();
    }
    
    // }}}
    

}

// }}} 

?>

